﻿using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace SlSyncWeb
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace="http://tempuri.org/")]
    [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
    public class FileReceiver : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string fileName=context.Request["filename"];

            using (FileStream file=File.Create(context.Server.MapPath("/")+fileName))
            {
                SaveFile(context.Request.InputStream, file);
            }
            context.Response.ContentType="text/plain";
            context.Response.Write("Hello World");
        }

        private void SaveFile(Stream stream, FileStream file)
        {
            byte[] buffer=new byte[4096];
            int bytesRead;

            while ((bytesRead=stream.Read(buffer, 0, buffer.Length))!=0)
            {
                file.Write(buffer, 0, bytesRead);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
